package com.csl.jsonpreference.test

import android.os.Parcel
import android.os.Parcelable
import com.csl.jsonpreference.bean.ConfigTYPE
import com.csl.jsonpreference.tag.Configurable
import com.google.gson.Gson


/**
 * aqua car 设备端车辆配置.
 */
@Configurable(discribe = "小车本地配置")
class AquaCarLocalConfig(){

    companion object {
        fun createForJson(str: String?): AquaCarLocalConfig {
            try {
                var config: AquaCarLocalConfig =
                    Gson().fromJson(str, AquaCarLocalConfig::class.java)

                return config
            } catch (e : java.lang.Exception) {
                return AquaCarLocalConfig()
            }
        }

    }



    @Configurable(discribe = "x最小值(0,100)", type = ConfigTYPE.NUMBER, index = 0)
    var offsetXMin: Int = 0
    @Configurable(discribe = "x最大值(0,100)", type = ConfigTYPE.NUMBER, index = 1)
    var offsetXMax: Int = 100


    @Configurable(discribe = "y最小值(0,100)", type = ConfigTYPE.NUMBER, index = 2)
    var offsetYMin: Int = 0
    @Configurable(discribe = "y最大值(0,100)", type = ConfigTYPE.NUMBER, index = 3)
    var offsetYMax: Int = 100

    @Configurable(discribe = "z最小值(0,100)", type = ConfigTYPE.NUMBER, index = 4)
    var offsetZMin: Int = 0
    @Configurable(discribe = "z最大值(0,100)", type = ConfigTYPE.NUMBER, index = 5)
    var offsetZMax: Int = 100

    constructor(parcel: Parcel) : this() {
        offsetXMin = parcel.readInt()
        offsetXMax = parcel.readInt()
        offsetYMin = parcel.readInt()
        offsetYMax = parcel.readInt()
        offsetZMin = parcel.readInt()
        offsetZMax = parcel.readInt()
    }


    fun toJsonString(): String {
        return Gson().toJson(this).toString()
    }



}